/*
 * @: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2022-03-10 09:49:01
 * @LastEditors: ziwei
 * @LastEditTime: 2022-03-10 11:48:15
 */
const EventEmitter = require('events')
const { response } = require('express')
const http = require('http')
class Network extends EventEmitter{
  fetchResource(options){
    return new Promise(resolve=>{
      let request = http.request(options,response=>{
        const headers = response.headers;
        const buffers = []
        response.on('data',()=>{
          buffers.push(buffer)
        })
        response.on('end',()=>{
          resolve({
            headers,
            body:Buffer.concat(buffers).toString()
          })
        })
      })
      request.end()
    })
  }
}
const network = new Network()
module.exports = network